package com.zhouyu.order;

import org.springframework.core.OrderComparator;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhaojy
 * @date 2025/10/15-5:12 下午
 */
public class TestOrder {
	public static void main(String[] args) {
		OrderOA orderA = new OrderOA();
		OrderOB orderB = new OrderOB();
		AnnotationAwareOrderComparator comparator = new AnnotationAwareOrderComparator();
		System.out.println(comparator.compare(orderA, orderB)); // 1

		List list = new ArrayList<>();
		list.add(orderA);
		list.add(orderB);

		// 按order值升序排序
		list.sort(comparator);

		// [com.zhouyu.order.OrderOB@7960847b, com.zhouyu.order.OrderOA@6a6824be]
		System.out.println(list);
	}

	void test() {
		OrderA orderA = new OrderA();
		OrderB orderB = new OrderB();
		OrderComparator comparator = new OrderComparator();
		System.out.println(comparator.compare(orderA, orderB)); // 1

		List list = new ArrayList<>();
		list.add(orderA);
		list.add(orderB);

		// 按order值升序排序
		list.sort(comparator);

		// [com.zhouyu.order.OrderB@7aec35a, com.zhouyu.order.OrderA@67424e82]
		System.out.println(list);  // B，A
	}
}
